/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package genomemap.cef.pui;

import cef.event.Event;
import cef.pui.EventConstructionException;
import cef.pui.EventImpl;
import cef.pui.pob.Builder;
import commons.core.ValueTypes;
import genomemap.cef.event.DrawAlignmentMap_Evt;
import genomemap.map.GenomeMap;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * Implements {@code DrawAlignmentMap_Evt} using the following properties.
 * <ul>
 * <li>{@code commons.builder.StringList2.url = stringlist2:xml//URL }<a href="cef/pui/pob/doc-files/StringList2.xml.txt">file format</a>, must accompany the <a href="cef/pui/pob/doc-files/StringList2.xsd.txt">schema</a></li>
 * </ul>
 *
 * @author Susanta Tewari
 * @version 1.0.0
 * @history Created on 10/02/2011
 * @since 1.0.0
 */
public final class DrawAlignmentMap_EvtImpl extends EventImpl implements DrawAlignmentMap_Evt {

    /** Field description */
    private final Builder<ValueTypes.StringList2> list2Builder;

    /**
     * Constructs ...
     *
     *
     * @param props event properties
     *
     * @throws EventConstructionException
     */
    public DrawAlignmentMap_EvtImpl(final Properties props) throws EventConstructionException {

        super(props);

        super.processEventProperties(getImplementedEventInterfaces());

        list2Builder = cef.pui.pob.Builders.of_StringList2_File(props, null);
    }

    /**
     * Method description
     *
     *
     * @return implemented event interfaces
     */
    @Override
    protected List<Class<? extends cef.event.Event>> getImplementedEventInterfaces() {

        final List<Class<? extends cef.event.Event>> result = new ArrayList<>(2);

        result.add(DrawAlignmentMap_Evt.class);
        result.add(Event.class);

        return result;
    }

    /**
     * Method description
     *
     *
     * @return list of maps
     */
    private List<ValueTypes.StringList> getStringList2() {
        return list2Builder.build().toStringLists();
    }

    /**
     * Method description
     *
     *
     * @return list of maps
     */
    @Override
    public List<? extends GenomeMap> getMaps() {

        final List<ValueTypes.StringList> list2 = getStringList2();
        final List<GenomeMap> maps              = new ArrayList<>(list2.size());

        for (final ValueTypes.StringList stringList : list2) {
            maps.add(new GenomeMap(stringList.getData(), stringList.getTitle()));
        }

        return maps;
    }
}
